package com.xixi.client;

//编程去实现客户端得初始化和关闭操作

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
    public class ClientInitClose {
        //自定义成员变量记录Socket和流对象
        private Socket socket;
        private ObjectOutputStream objectOutputStream;
        private ObjectInputStream objectInputStream;

        public ObjectOutputStream getObjectOutputStream() {
            return objectOutputStream;
        }

    public ObjectInputStream getObjectInputStream() {
        return objectInputStream;
    }

    //自定义成员方法实现客户端的初始化操作
    public void clientInt() throws IOException {
       //1.创建Scoket类型得对象并指定服务器得通信地址和端口号
        /*Socket*/ socket=new Socket(InetAddress.getLocalHost(),10086);
        System.out.println("连接服务器成功");
        //2.使用输入输出流通信
        /*ObjectOutputStream*/ objectOutputStream=new ObjectOutputStream(socket.getOutputStream());
        /*ObjectInputStream*/ objectInputStream=new ObjectInputStream(socket.getInputStream());
        System.out.println("连接服务器成功");
        //3.关闭Scoket并释放有关得资源
       // socket.close();
    }
    public void clientClose() throws IOException {
        //3.关闭Scoket并释放有关得资源
        objectInputStream.close();
        objectOutputStream.close();
        socket.close();
        System.out.println("客户端成功关闭");
    }
}
